""" 
    twExtJS - ToscaWidgets wrapper for ExtJS (see http://extjs.com)
    
    Distributed under the terms of Lesser GNU Public License.
    
    (c) 2007 - Ricardo Girardi Sixel 
"""

#from toscawidgets.widgets.forms import Form,FormField
from toscawidgets.widgets.extJS.panel import Panel
from toscawidgets.core import Widget
from toscawidgets.widgets.extJS.core import Component
    
class FormPanel(Panel):
#    template = "mako:toscawidgets.widgets.extJS.templates.form.formpanel"
    xtype='form'
    labelWidth= 75 # label settings here cascade unless overridden
    labelAlign= 'top'
    url = ''
    frame = True
    title = 'Title'
    name = 'Name'
    bodyStyle = 'padding:5px 5px 0'
    width = 350
    defaults = None
    defaultType = 'textfield'
    layout = 'column'
    buttonAlign = 'right'
    store=None
    buttons=[]    
    params=Panel.params|frozenset(['labelWidth','labelAlign','url','frame','title','name',
            'bodyStyle','width','defaults','defaultType','buttonAlign','store','layout',
            'buttons'])
    
   

class Field(Component):
    xtype='field'
#    template = "mako:toscawidgets.widgets.extJS.templates.form.field"
    params=Component.params | frozenset(['fieldLabel','name'])
    engine_name = 'mako'
    fieldLabel = 'field'
    name='field'
    width=90
    embedded=False


class FieldSet(Panel):
#    template = "mako:toscawidgets.widgets.extJS.templates.form.fieldset"
    xtype = 'fieldset'
    checkboxToggle = False

    title = None
    autoHeight = True
    defaults =  "{width : 210}"
    defaultType = 'textfield'
    collapsed = False
    collapsible=False
    width=None
    height=None
    labelWidth=75
    layout='column'
    bodyBorder=True

    params=Panel.params | frozenset(['checkboxToggle','title','autoHeight','defaults','defaultType',
            'collapsed','items','width','labelWidth','height','collapsed','collapsible','layout',
            'bodyBorder'])
    items = []

class TextField(Field):
    """A text field"""
    template = "mako:toscawidgets.widgets.extJS.templates.form.textfield"
    xtype='textfield'
    fieldLabel = 'textField'
    name = 'textField'
    allowBlank = True
    value = '' 
    vtype = ''
    params = Field.params | frozenset( ['fieldLabel','name','allowBlank','value','vtype','width','embedded'])
    
class DateField(Field):
    """A date field"""
    template = "mako:toscawidgets.widgets.extJS.templates.form.datefield"
    xtype='datefield'
    fieldLabel = 'datefield'
    name = 'datefield'
    allowBlank = True
    value = '' 
    vtype = ''
    params = ['xtype','fieldLabel','name','allowBlank','value','vtype','width','embedded'] 
    format = 'd-m-Y'   
    
class HiddenField(Field):
    """ Hidden field place holder """
    type = "hidden"
#    template = "mako:toscawidgets.widgets.extJS.templates.form.hiddenfield"
    xtype='hidden'
    name = 'hiddenField'
    default = ''
    fieldLabel = 'hidden'
    
class Checkbox(Field):
    """A checkbox field"""
    template = "mako:toscawidgets.widgets.extJS.templates.form.checkbox"
    xtype='checkbox'
    fieldLabel = 'checkbox'
    name = 'checkbox'
    allowBlank = True
    value = '' 
    vtype = ''
    params = ['xtype','fieldLabel','name','allowBlank','value','vtype','embedded'] 
     
    
class NumberField(Field):
    """A number field"""   

class ComboBox(Field):
    """"A combobox field"""
    template = "mako:toscawidgets.widgets.extJS.templates.form.combobox"
    store= None
    displayField=''
    valueField='id'
    hiddenName='id'
    typeAhead= True
    mode= 'local'
    triggerAction= 'all'
    emptyText='Select...'
    selectOnFocus=True
    applyTo= ''
    fieldLabel='combobox'
    params=['store','displayField','typeAhead','mode','triggerAction','emptyText',
            'selectOnFocus','applyTo','valueField','transform','hiddenName','fieldLabel']
    transform='' 
    